<?php
/**
 * Created by PhpStorm.
 * User: Jerry
 * Date: 2017/1/5
 * Time: 16:29
 */

namespace SDXApi\Controller;


use SDXApi\Service\BuyNowNoticeService;

/**
 * Class BuyNowNoticeController
 * @package SDXApi\Controller
 */
class BuyNowNoticeController extends AppController
{
	/**
	 * 订阅商品秒杀通知
	 * Created by Jerry
	 */
	public function add_buy_now_notice()
	{
	    //第二个参数如果不存在则返回0，以int的方式过滤数据
		$goods_id = I('post.goods_id', 0, 'int');
		$user_id = I('post.uid', 0, 'int');

		if (empty($goods_id) || empty($user_id)) {
			returnApiError('非法请求');
		}

		$time = time();
		$data = array(
			'goods_id'		=>	$goods_id,
			'user_id'		=>	$user_id,
			'notice_time'	=>	$time,
		);

		$buyNowService = new BuyNowNoticeService();
		$noticeRs = $buyNowService->storeNotice($data);

		if ($noticeRs->getNoticeError() != '') {
			returnApiError($noticeRs->getNoticeError());
		}

		$data = array(
			'msg'	=>	'订阅成功'
		);
		returnApiSuccess($data);
	}
}